﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="CenterEquipment.aspx.cs" Inherits="WebForms_CenterEquipment" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
    <section class="featured">
        <div class="content-wrapper" dir="rtl">
            تجهیزات مراکز
        </div>
    </section>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
    <script type="text/javascript">
        function Mandatory(sender, e) {
            e.IsValid = (e.Value != '0');
        }
    </script>
    <asp:MultiView ID="MultiView" runat="server" ActiveViewIndex="0">
        <asp:View ID="ShowView" runat="server">
            <div dir="rtl" style="width: 100%;">
                <asp:ImageButton ID="SearchImageButton" runat="server" OnClick="SearchImageButton_Click"
                    SkinID="SearchButton" />
                <asp:ImageButton ID="ClearImageButton" runat="server" OnClick="ClearImageButton_Click"
                    OnClientClick="return false;" SkinID="ClearButton" />
                <br />
                <asp:Label ID="CenterNameLabel" runat="server" Text="نام مرکز:" SkinID="Caption" CssClass="lable"></asp:Label>
                <asp:TextBox ID="CenterNameTextBox" runat="server" SkinID="TextBox"></asp:TextBox>
                <asp:Label ID="CenterPassLabel" runat="server" Text="رمز شناسایی:" SkinID="Caption" CssClass="lable"></asp:Label>
                <asp:TextBox ID="CenterPassTextBox" runat="server" SkinID="TextBox"></asp:TextBox>
                <asp:Label ID="SizePageLabel" runat="server" Text="سایز صفحه:" SkinID="Caption" CssClass="lable"></asp:Label>
                <asp:DropDownList ID="PageSizeDropDownList" SkinID="SearchDropDownList" runat="server">
                    <asp:ListItem Selected="True" Value="5">[پیش فرض]</asp:ListItem>
                    <asp:ListItem Value="5">5 رکورد</asp:ListItem>
                    <asp:ListItem Value="10">10 رکورد</asp:ListItem>
                    <asp:ListItem Value="15">15 رکورد</asp:ListItem>
                    <asp:ListItem Value="20">20 رکورد</asp:ListItem>
                    <asp:ListItem Value="25">25 رکورد</asp:ListItem>
                    <asp:ListItem Value="1000000">تمام رکورد ها</asp:ListItem>
                </asp:DropDownList>
            </div>
            <br />
            <div style="float: right; width: 90%; vertical-align: top;" dir="rtl" class="gvclass">
                <asp:GridView ID="CenterGridView" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                    DataKeyNames="PkCenterID" DataSourceID="CenterEntityDataSource" HorizontalAlign="Center"
                    OnSelectedIndexChanged="CenterGridView_SelectedIndexChanged" Width="100%" AllowSorting="false"
                    PageSize="5">
                    <Columns>
                        <asp:BoundField DataField="PkCenterID" HeaderText="PkCenterID" ReadOnly="True"
                            Visible="false" SortExpression="PkCenterID" />
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:ImageButton ID="SelectImageButton" runat="server" CommandName="Select" SkinID="SelectButton" />
                            </ItemTemplate>
                            <ItemStyle Width="25px" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="CenterName" HeaderText="مرکز" ReadOnly="True" SortExpression="CenterName" />
                        <asp:BoundField DataField="CenterPass" HeaderText="رمز شناسایی مرکز" ReadOnly="True" SortExpression="CenterPass" />
                    </Columns>
                </asp:GridView>
            </div>
        </asp:View>
        <asp:View ID="EditView" runat="server">
            <div dir="rtl" style="width: 5%; float: right">&nbsp;</div>
            <div dir="rtl" style="width: 40%; float: right" class="gvclass">
                <asp:Label ID="CenterLabel" runat="server" Text="" Width="200px" Font-Bold="true"></asp:Label>
                <asp:LinkButton ID="ReturnLinkButton" runat="server" OnClick="ReturnLinkButton_Click" CssClass="button">بازگشت</asp:LinkButton>
                <br />
                <asp:GridView ID="CenterEquipmentGridView" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                    DataKeyNames="FkCenterID,FkEquipmentID" DataSourceID="CenterEquipmentEntityDataSource"
                    HorizontalAlign="Center" OnSelectedIndexChanged="CenterEquipmentGridView_SelectedIndexChanged"
                    AllowSorting="True" PageSize="5">
                    <Columns>
                        <asp:BoundField DataField="FkCenterID" HeaderText="FkCenterID" ReadOnly="True"
                            SortExpression="FkCenterID" Visible="false" />
                        <asp:BoundField DataField="FKEquipmentID" HeaderText="FKEquipmentID" ReadOnly="True"
                            SortExpression="FKEquipmentID" Visible="false" />
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:ImageButton ID="SelectImageButton" runat="server" CommandName="Select" SkinID="SelectButton" />
                            </ItemTemplate>
                            <ItemStyle Width="25px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="تجهیزات" SortExpression="FkEquipmentID">
                            <ItemTemplate>
                                <asp:DropDownList ID="EquipmentDropDownList" runat="server" Enabled="False" SkinID="GridDropDownList"
                                    DataSourceID="EquipmentEntityDataSource" DataTextField="Name" DataValueField="ID"
                                    SelectedValue='<%# Bind("FkEquipmentID") %>'>
                                </asp:DropDownList>
                            </ItemTemplate>
                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="200px" />
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="Count" HeaderText="تعداد" ReadOnly="True"
                            SortExpression="Count">
                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="70px" />
                        </asp:BoundField>
                    </Columns>
                </asp:GridView>
            </div>
            <div dir="rtl" style="width: 5%; float: right">&nbsp;</div>
            <div dir="rtl" style="width:50%; float: left" class="gvclass">
                <br />
                <asp:FormView ID="CenterEquipmentFormView" runat="server" DataSourceID="CenterEquipmentEntityDataSource"
                    DataKeyNames="FkCenterID,FkEquipmentID" DefaultMode="Insert" OnItemCommand="CenterEquipmentFormView_ItemCommand" Width="100%">
                    <EditItemTemplate>
                        <asp:Label ID="EquipmentLabel" runat="server" Text="تجهیزات:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:DropDownList ID="EquipmentDropDownList" Enabled="false" runat="server" DataSourceID="EquipmentEntityDataSource"
                            DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("FkEquipmentID") %>'>
                        </asp:DropDownList>
                        <asp:CustomValidator ID="EquipmentCustomValidator" runat="server" ClientValidationFunction=" Mandatory"
                            ControlToValidate="EquipmentDropDownList" Display="Dynamic" ErrorMessage="*" ValidateEmptyText="True"
                            ValidationGroup="Update"></asp:CustomValidator>
                        <asp:HiddenField ID="CenterIDHiddenField" runat="server"
                            Value='<%# Bind("FkCenterID") %>' />
                        <br />
                                <asp:Label ID="CountLabel" runat="server" Text="تعداد:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="CountTextBox" runat="server" Text='<%# Bind("Count") %>' />
                        <asp:RequiredFieldValidator ID="CountRequiredFieldValidator" runat="server" ControlToValidate="CountTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="CountRangeValidator" runat="server" ControlToValidate="CountTextBox" Display="Dynamic"
                            ErrorMessage=" عددی بین 1 و 255 وارد کنید" Type="Integer" ValidationGroup="Update" MinimumValue="1" MaximumValue="255"></asp:RangeValidator>
                      <br />
                                <div style="float: left; padding: 5px;">
                                    <asp:LinkButton ID="DeleteLinkButton" runat="server" CausesValidation="False" CommandName="Delete" CssClass="button"
                                        OnClientClick="if (!confirm('آيا از حذف مطمئن هستيد؟')) return false;" Text="حذف" />
                                    <asp:LinkButton ID="UpdateLinkButton" runat="server" CommandName="Update"
                                        ValidationGroup="Update" OnClientClick="if (!confirm('آيا از اعمال تغییرات مطمئن هستيد؟')) return false;" Text="ویرایش" CssClass="button" />
                                    <asp:LinkButton ID="CancelLinkButton" runat="server" CommandName="Cancel" Text="انصراف" CssClass="button" />

                                </div>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:Label ID="EquipmentLabel" runat="server" Text="تجهیزات:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:DropDownList ID="EquipmentDropDownList" runat="server" DataSourceID="EquipmentEntityDataSource"
                            DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("FkEquipmentID") %>'>
                        </asp:DropDownList>
                        <asp:CustomValidator ID="EquipmentCustomValidator" runat="server" ClientValidationFunction=" Mandatory"
                            ControlToValidate="EquipmentDropDownList" Display="Dynamic" ErrorMessage="*" ValidateEmptyText="True"
                            ValidationGroup="Insert"></asp:CustomValidator>
                        <asp:HiddenField ID="CenterIDHiddenField" runat="server"
                            Value='<%# Bind("FkCenterID") %>' />
                       <br />
                                <asp:Label ID="CountLabel" runat="server" Text="تعداد:" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="CountTextBox" runat="server" Text='<%# Bind("Count") %>' />
                        <asp:RequiredFieldValidator ID="CountRequiredFieldValidator" runat="server" ControlToValidate="CountTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="CountRangeValidator" runat="server" ControlToValidate="CountTextBox" Display="Dynamic"
                            ErrorMessage=" عددی بین 1 و 255 وارد کنید" Type="Integer" ValidationGroup="Update" MinimumValue="1" MaximumValue="255"></asp:RangeValidator>
                        <br />
                                <div style="float: left; padding: 5px;">
                                    <asp:LinkButton ID="InsertLinkButton" runat="server" CommandName="Insert" Text="ایجاد" CssClass="button"
                                        ValidationGroup="Insert" OnClick="InsertLinkButton_Click" />

                                    <asp:LinkButton ID="CancelLinkButton" runat="server" CommandName="Cancel" Text="انصراف" CssClass="button" />
                                </div>
                    </InsertItemTemplate>
                </asp:FormView>
            </div>
        </asp:View>
    </asp:MultiView>

    <asp:EntityDataSource ID="CenterEntityDataSource" runat="server" ConnectionString="name=ICTBillingEntities" DefaultContainerName="ICTBillingEntities"
        EnableFlattening="False" EntitySetName="tbCenters"
        Where="(@CenterName is null || it.CenterName LIKE '%' + @CenterName + '%') AND (@CenterPass is null || it.CenterPass LIKE '%' + @CenterPass + '%')">
        <WhereParameters>
            <asp:ControlParameter ControlID="CenterNameTextBox" Name="CenterName" Type="String" />
            <asp:ControlParameter ControlID="CenterPassTextBox" Name="CenterPass" Type="String" />
        </WhereParameters>
    </asp:EntityDataSource>

    <asp:EntityDataSource ID="CenterEquipmentEntityDataSource" runat="server" ConnectionString="name=ICTBillingEntities"
        DefaultContainerName="ICTBillingEntities" EnableDelete="True" EnableInsert="True"
        EnableUpdate="True" EntitySetName="tbCenterEquipments" OnDeleted="CenterEquipmentEntityDataSource_Command"
        OnInserted="CenterEquipmentEntityDataSource_Command" OnUpdated="CenterEquipmentEntityDataSource_Command"
        Where="it.FkCenterID = @PkCenterID" Include="tbCenter,tbEquipment" EnableFlattening="False">
        <WhereParameters>
            <asp:ControlParameter ControlID="CenterIDHiddenField" DbType="Int32" Name="PkCenterID"
                PropertyName="Value" DefaultValue="0" />
        </WhereParameters>
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="EquipmentEntityDataSource" runat="server" ConnectionString="name=ICTBillingEntities"
        DefaultContainerName="ICTBillingEntities"
        CommandText="(SELECT  it.[PkEquipmentID] As ID, it.[EquipmentName] As Name FROM ICTBillingEntities.tbEquipments AS it) UNION (SELECT x.[ConstantValue] as ID,x.[ConstantName] As Name from ICTBillingEntities.tbConstants as x where x.PkConstantID=2)"
        EnableFlattening="False">
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="LocationEntityDataSource" runat="server" ConnectionString="name=ICTBillingEntities" DefaultContainerName="ICTBillingEntities"
        EnableFlattening="False"
        CommandText="(SELECT  it.[PkLocationID] As ID, it.[LocationName] As Name FROM ICTBillingEntities.tbLocations AS it) UNION (SELECT x.[ConstantValue] as ID,x.[ConstantName] As Name from ICTBillingEntities.tbConstants as x where x.PkConstantID=2)">
    </asp:EntityDataSource>

    <asp:HiddenField ID="CenterIDHiddenField" runat="server" />
</asp:Content>

